<template>
  <!-- 这种选农业类型不用重复写样式 -->
  <div class="farmtypeview">
    <!-- 农业类型 -->
    <div class="select-farmtype">
      <div v-for="(item, index) in basefarmtype" :key="index" class="farmtypebutton" :class="item.farmingTypeId === nowselectmessage.farmingTypeId
        ? 'farmtypebutton-active'
        : ''
        " @click="slecttype(item)">
        <div class="but-line">
          {{ item.description }}
        </div>
      </div>
    </div>
    <!-- 框框 -->
    <div class="select-border">
      <slot name="farmtypemain" :typename="nowselectmessage"> </slot>
    </div>
  </div>
</template>
<script>
import axios from 'axios';
export default {
  name: "SelectFarmType",
  data() {
    return {
      basefarmtype: [
        {
          "description": "大田种植",
          "farmingTypeId": 1,
          "farmingTypeName": "大田种植"
        },
        {
          "description": "大棚种植",
          "farmingTypeId": 2,
          "farmingTypeName": "大棚种植"
        },
        {
          "description": "畜牧养殖",
          "farmingTypeId": 3,
          "farmingTypeName": "畜牧养殖"
        },
        {
          "description": "水产养殖",
          "farmingTypeId": 4,
          "farmingTypeName": "水产养殖"
        },
        {
          "description": "工厂养鱼",
          "farmingTypeId": 5,
          "farmingTypeName": "工厂养鱼"
        }
      ],
      nowselectmessage: { description: "大田种植", farmingTypeId: 1 }
    };
  },
  mounted() {
    this.getallfarmlist()
  },
  methods: {
    // 获取所有农业类型
    getallfarmlist() {
      axios({
        method: "GET",
        url: `${this.$webUrl}/productionv2/farmingType/queryList`
      }).then(response => {
        let farmmes = response.data.data
        if (farmmes && farmmes[0]) {
          this.basefarmtype = farmmes
        }
      })
    },
    slecttype(e) {
      this.nowselectmessage = e;
      this.$emit("farmtypemessage", e);
    }
  }
};
</script>
<style lang="scss" scoped>
@import "~@/styles/variables.scss";

.farmtypeview {
  width: 100%;
  height: 100%;
  overflow: hidden;

  // background-color: antiquewhite;
  .select-farmtype {
    margin-bottom: 25px;
    width: 100%;
    height: 50px;
    overflow: hidden;
    display: flex;
    flex-direction: row;

    &:first-of-type {
      margin-left: 15px;
    }

    &:last-of-type {
      margin-right: 15px;
    }

    .farmtypebutton {
      width: 159px;
      min-width: 159px;
      height: 40px;
      background: #00525D;
      border-radius: 48px 48px 48px 48px;
      opacity: 1;
      border: 1px solid #005b5f;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      margin-right: 12px;

      .but-line {
        width: 80px;
        height: 28px;
        font-size: 20px;
        font-family: PingFang SC-Regular, PingFang SC;
        font-weight: 400;
        color: $textColor;
        line-height: 28px;
      }

    }

    .farmtypebutton-active {
      background: #009fa5;
    }

    .farmtypebutton:hover {
      background: #009fa5;
    }
  }

  .select-border {
    margin-top: -30px;
    width: 100%;
    height: calc(100% - 20px);
    border: 2px dashed #01444e;
    padding: 10px 10px;
    overflow-y: auto;
  }
}
</style>
